<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: cross_selling.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

defined('_VALID_XTC') or die('Direct Access to this location is not allowed.');

$article_data = $db->db_query("SELECT
									products_name
								FROM
									".TABLE_PRODUCTS_DESCRIPTION."
								WHERE
									products_id = '".(int)$_GET['current_product_id']."'
								AND
									language_id = '".$_SESSION['languages_id']."'");

$cross_sell_groups = get_cross_sell_groups();

function buildCAT($catID) {
	global $db;

	$cat = array ();
	$tmpID = $catID;

	while (getParent($catID) != 0 || $catID != 0) {
		$cat_data = $db->db_query("SELECT
										categories_name
									FROM
										".TABLE_CATEGORIES_DESCRIPTION."
									WHERE
										categories_id = '".$catID."'
									AND
										language_id = '".$_SESSION['languages_id']."'");

		$catID = getParent($catID);
		$cat[] = $cat_data->fields['categories_name'];
	}
	$catStr = '';
	for ($i = count($cat); $i > 0; $i --) {
		$catStr .= $cat[$i -1].' > ';
	}
	return $catStr;
}

function getParent($catID) {
	global $db;

	$parent_data = $db->db_query("SELECT
										parent_id
									FROM
										".TABLE_CATEGORIES."
									WHERE
										categories_id = '".$catID."'");
	return $parent_data->fields['parent_id'];
}
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo CROSS_SELLING.' : '.$article_data->fields['products_name']; ?></td>
          </tr>
          <tr>
            <td colspan="">
            	<a class="button" href="<?php echo href_link(FILENAME_CATEGORIES,'cPath='.$_GET['cpath'].'&pID='.$_GET['current_product_id']); ?>"><?php echo BUTTON_BACK; ?></a></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
	  <tr>
        <td>

        <?php

echo draw_form('cross_selling', FILENAME_CATEGORIES, '', 'GET', '');
echo draw_hidden_field(session_name(), session_id());
echo draw_hidden_field('action', 'edit_crossselling');
echo draw_hidden_field('special', 'edit');
echo draw_hidden_field('current_product_id', $_GET['current_product_id']);
echo draw_hidden_field('cpath', $_GET['cpath']);
?>


 <table width="100%" border="0">
  <tr>
    <td class="dataTableHeadingContent" width="1%"><?php echo HEADING_DEL; ?></td>
    <td class="dataTableHeadingContent" width="4%"><?php echo HEADING_SORTING; ?></td>
    <td class="dataTableHeadingContent" width="5%"><?php echo HEADING_GROUP; ?></td>
    <td class="dataTableHeadingContent" width="15%"><?php echo HEADING_MODEL; ?></td>
    <td class="dataTableHeadingContent" width="34%"><?php echo HEADING_NAME; ?></td>
    <td class="dataTableHeadingContent" width="42%"><?php echo HEADING_CATEGORY; ?></td>
  </tr>
<?php


$cross_data = $db->db_query("SELECT
									cs.ID,
									cs.products_id,
									pd.products_name,
									cs.sort_order,
									p.products_model,
									p.products_id,
									cs.products_xsell_grp_name_id
								FROM
									".TABLE_PRODUCTS_XSELL." cs,
									".TABLE_PRODUCTS_DESCRIPTION." pd,
									".TABLE_PRODUCTS." p
								WHERE
									cs.products_id = '".(int)$_GET['current_product_id']."'
								AND
									cs.xsell_id=p.products_id
								AND
									p.products_id=pd.products_id
								AND
									pd.language_id = '".$_SESSION['languages_id']."'
								ORDER BY
									cs.sort_order");

if($cross_data->_numOfRows < 1) {
?>
  <tr>
    <td class="categories_view_data" colspan="5">- kein Eintrag -</td>
  </tr>
<?php


}
while(!$cross_data->EOF) {
	$categorie_data = $db->db_query("SELECT
											categories_id
										FROM
											".TABLE_PRODUCTS_TO_CATEGORIES."
										WHERE
											products_id='".$cross_data->fields['products_id']."' LIMIT 0,1");
?>

  <tr>
    <td class="categories_view_data"><input type="checkbox" name="ids[]" value="<?php echo $cross_data->fields['ID']; ?>"></td>
    <td class="categories_view_data"><input name="sort[<?php echo $cross_data->fields['ID']; ?>]" type="text" size="3" value="<?php echo $cross_data->fields['sort_order']; ?>"></td>

    <td class="categories_view_data" style="text-align: left;"><?php echo draw_pull_down_menu('group_name['.$cross_data->fields['ID'].']', $cross_sell_groups,$cross_data->fields['products_xsell_grp_name_id']); ?></td>

    <td class="categories_view_data" style="text-align: left;"><?php echo $cross_data->fields['products_model']; ?></td>
    <td class="categories_view_data" style="text-align: left;"><?php echo $cross_data->fields['products_name']; ?></td>
    <td class="categories_view_data" style="text-align: left;"><?php echo buildCAT($categorie_data->fields['categories_id']); ?> </td>
  </tr>

<?php
	$cross_data->MoveNext();
} ?>
</table>
<input type="submit" class="button" value="<?php echo BUTTON_SAVE; ?>" onClick="return confirm('<?php echo SAVE_ENTRY; ?>')">
<?php echo '</form>'; ?>
</td>
</tr>
<tr>
<td class="pageHeading"><hr noshade><?php echo CROSS_SELLING_SEARCH; ?>

<table>
<tr class="dataTableRow">
<?php


	echo draw_form('product_search', FILENAME_CATEGORIES, '', 'GET');
	echo draw_hidden_field('action', 'edit_crossselling');
	echo draw_hidden_field(session_name(), session_id());
	echo draw_hidden_field('current_product_id', $_GET['current_product_id']);
	echo draw_hidden_field('cpath', $_GET['cpath']);
?>
<td class="dataTableContent" width="40"><?php echo draw_input_field('search', '', 'size="30"');?></td>
<td class="dataTableContent">
<?php


	echo '<input type="submit" class="button" onClick="this.blur();" value="' . BUTTON_SEARCH . '"/>';
	echo '</form></td>';
?>
</tr>
</table>
<hr noshade="" />
</td>
</tr>
<tr>
<td>

<?php


	// search results
	if ($_GET['search']) {
		echo draw_form('product_search', FILENAME_CATEGORIES, '', 'GET');
		echo draw_hidden_field('action', 'edit_crossselling');
		echo draw_hidden_field('special', 'add_entries');
		echo draw_hidden_field('current_product_id', $_GET['current_product_id']);
		echo draw_hidden_field('cpath', $_GET['cpath']);
?>
 <table width="100%" border="0">
  <tr>
    <td class="dataTableHeadingContent" width="9%"><?php echo HEADING_ADD; ?></td>
    <td class="dataTableHeadingContent" width="10%"><?php echo HEADING_GROUP; ?></td>
    <td class="dataTableHeadingContent" width="10%"><?php echo HEADING_MODEL; ?></td>
    <td class="dataTableHeadingContent" width="34%"><?php echo HEADING_NAME; ?></td>
    <td class="dataTableHeadingContent" width="42%"><?php echo HEADING_CATEGORY; ?></td>
  </tr>
  <?php


		$search_data = $db->db_query("SELECT
											*
										FROM
											".TABLE_PRODUCTS_DESCRIPTION." pd,
											".TABLE_PRODUCTS." p
										WHERE
											p.products_id = pd.products_id
										AND
											pd.language_id = '".$_SESSION['languages_id']."'
										AND
											p.products_id != '".$_GET['current_product_id']."'
										AND
											(pd.products_name LIKE '%".$_GET['search']."%' OR p.products_model LIKE '%".$_GET['search']."%')");

		while (!$search_data->EOF) {
			$categorie = $db->db_query("SELECT
											categories_id
										FROM
											".TABLE_PRODUCTS_TO_CATEGORIES."
										WHERE
											products_id='".$search_data->fields['products_id']."'
										LIMIT 0,1");
		?>
		  <tr>
		    <td class="categories_view_data"><input type="checkbox" name="ids[]" value="<?php echo $search_data->fields['products_id']; ?>"></td>
		    <td class="categories_view_data" style="text-align: left;"><?php echo draw_pull_down_menu('group_name['.$search_data->fields['products_id'].']',$cross_sell_groups); ?></td>
		    <td class="categories_view_data" style="text-align: left;"><?php echo $search_data->fields['products_model']; ?></td>
		    <td class="categories_view_data" style="text-align: left;"><?php echo $search_data->fields['products_name']; ?></td>
		    <td class="categories_view_data" style="text-align: left;"><?php echo buildCAT($categorie->fields['categories_id']); ?> </td>
		  </tr>

		<?php
			$search_data->MoveNext();
		}
	?>
</table>
<input type="submit" class="button" value="<?php echo BUTTON_SAVE; ?>" onClick="return confirm('<?php echo SAVE_ENTRY; ?>')">
</form>
<?php
}
?>